package com.weactivity.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weactivity.dto.ContactDTO;
import com.weactivity.dto.UserDTO;
import com.weactivity.entity.Contact;
import com.weactivity.mapper.ContactMapper;
import com.weactivity.service.ContactService;
import com.weactivity.utils.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ContactServiceImpl extends ServiceImpl<ContactMapper, Contact> implements ContactService {

    @Autowired
    private ContactMapper contactMapper;

    /**
     * 根据用户id查找用户联系人
     * @return
     */
    @Override
    public List<ContactDTO> showContact() {

        UserDTO user = UserHolder.getUser();

      List<ContactDTO> contactDTOList =  contactMapper.findAllContact(user.getId());
        return contactDTOList;

    }

    @Override
    public int remark(ContactDTO contactDTO) {
            UserDTO userDTO = UserHolder.getUser();
           int count =  contactMapper.remark(userDTO.getId(),contactDTO.getRemark(),contactDTO.getMateId());
           return count;

    }

    @Override
    public int deleteById(int mateId) {
        UserDTO userDTO = UserHolder.getUser();

        int count = contactMapper.deleteByMateId(userDTO.getId(),mateId);

        return count;
    }
}
